---
title: "Cereal Blast Tracker "
output:
flexdashboard::flex_dashboard:
orientation: rows
source_code: embed
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(flexdashboard)
library(prettydoc)
library(readxl)
library(tidyverse)
library(crosstalk)
library(plotly)
library(viridis)
library(gsheet)
library(leaflet.providers)
```
```{r load data, message=FALSE, warning=FALSE, include=FALSE}
Sys.setlocale("LC_ALL", "pt_BR.UTF-8")
mg_prod <- gsheet2tbl("https://docs.google.com/spreadsheets/d/13xAflAQ-x78Vkq0O0jUEkUxHPq5G1R4gwqzillMxoTo/edit?usp=sharing")
wb1 <- gsheet2tbl("https://docs.google.com/spreadsheets/d/1iYPjVBNXqwrNwp0lQI2YZnUChfSjVn3b5guuxnYS144/edit?usp=sharing")
wb_all <- wb1 %>%
filter(sample != 0) %>%
filter(region != "UNEMAT") %>%
mutate(id = case_when(
is.na(species) ~ "No",
TRUE ~ "Yes"
)) %>%
mutate(wheat = case_when(
host == "Triticum aestivum" ~ "Wheat",
TRUE ~ "Non-wheat")) %>%
dplyr::select(code, sample, lat, long, host, city, date, year, PstI_specie, species, wheat, DNA_extraction)
set.seed(1000)
wb_all$lat <- round(jitter(wb_all$lat, factor = 1, amount = 0.02), 4)
wb_all$long <- round(jitter(wb_all$long, factor = 1, amount = 0.02), 4)
wb_grass <- wb1 %>%
filter(sample != 0) %>%
filter(region != "UNEMAT") %>%
mutate(id = case_when(
is.na(species) ~ "No",
TRUE ~ "Yes"
)) %>%
filter(host == "Eleusine indica" | host == "Panicum maximum" | host == "Urochloa brizantha" | host == "Rhynchelytrum roseum" | host == "Urochloa humidicola" | host == "Urochloa plantaginea" | host == "Cynodon plectostachyus") %>%
mutate(host2 = case_when(
host == "Urochloa brizantha" ~ "Urochloa spp.",
host == "Urochloa humidicola" ~ "Urochloa spp.",
host == "Urochloa plantaginea" ~ "Urochloa spp.",
TRUE ~ host
))
set.seed(1000)
wb_grass$lat <- round(jitter(wb_grass$lat, factor = 1, amount = 0.01), 4)
wb_grass$long <- round(jitter(wb_grass$long, factor = 1, amount = 0.01), 4)
```
```{r all table, echo=FALSE}
library(crosstalk)
library(leaflet)
library(leaflet.extras)
library(DT)
sd <- SharedData$new(wb_all)
sd_grass <- SharedData$new(wb_grass)
```
Inputs {.sidebar}
-------------------------------------
### Quick filter
```{r}
#filter_slider("year", "Select years", sd, ~year)
filter_select("host", "Select host", sd, ~host)
filter_select("PstI_specie", "Pyricularia spp.", sd, ~PstI_specie)
filter_checkbox("DNA_extraction", "DNA extraction", sd, ~DNA_extraction, inline = TRUE)
filter_checkbox("wheat", "Host group", sd, ~wheat, inline = TRUE)
```
Row {data-height=300}
-------------------------------------
### Plot host species
```{r}
sd %>%
plot_ly(x = ~ wheat,
color = ~wheat,
colors = "Set2") %>%
layout(barmode = 'stack',
margin=list(l=20,r=20,t=20,b=20))
```
### All hosts
```{r}
library(RColorBrewer)
library(htmltools)
pal <- colorFactor("Set2", domain = c("Wheat", "Non-wheat"))
leaflet(data = sd) %>%
setView(-47.96101, -19.72314, zoom = 5) %>%
addProviderTiles(providers$CartoDB.Voyager) %>%
addCircleMarkers(
group = "wheat",
radius = 6,
fillOpacity = 1,
weight = 0.5,
label = paste(wb_all$host, "- Details"),
fillColor = ~ pal(wheat),
popup = paste(
"Code:", wb_all$"code", "", "
",
"Field sample:", wb_all$"sample", "", "
",
"Host:", wb_all$"host", "", "
",
"Tissue:", wb_all$"tissue", "", "
",
"Field sample:", wb_all$"sample", "", "
",
"City:", wb_all$"city", "", "
",
"Year:", wb_all$"year", "", "
",
"DNA extraction:", wb_all$"DNA_extraction", "", "
",
"Species:", wb_all$"PstI_specie", "", "
",
"OBS:", wb_all$"observation", "", "
"
)
) %>%
addLegend("bottomleft",
pal = pal,
values = ~wheat,
title = "Host",
opacity = 1
) %>%
addEasyButton(easyButton(
icon = "fa-globe", title = "Back to initial view",
onClick = JS("function(btn, map){ map.setZoom(2); }")
))
```
Row
----------
### Grid display
```{r}
datatable(sd,
extensions = c("Buttons", "ColReorder"),
escape = TRUE, rownames = FALSE,
class = "cell-border stripe",
options = list(
dom = "Bfrtip", buttons = c("excel", "pdf"), deferRender = TRUE,
scrollY = 50,
pageLength = 15,
scroller = TRUE,
colReorder = TRUE
)
)
```